home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / UUCICO / DCPXFER.C < prev    next >
C/C++ Source or Header  |  1993-10-02  |  52KB  |  1,420 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    d c p x f e r . c                                               */
  3. /*                                                                    */
  4. /*    Procotol independent transfer level for UUCICO                  */
  5. /*                                                                    */
  6. /*    Stuart Lynne May/87                                             */
  7. /*                                                                    */
  8. /*    Copyright (c) Richard H. Lamb 1985, 1986, 1987                  */
  9. /*    Changes Copyright (c) Stuart Lynne 1987                         */
  10. /*    Changes Copyright (c) Jordan Brown 1990, 1991                   */
  11. /*--------------------------------------------------------------------*/
  12.  
  13. /*--------------------------------------------------------------------*/
  14. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  15. /*       Wonderworks.                                                 */
  16. /*                                                                    */
  17. /*       All rights reserved except those explicitly granted by       */
  18. /*       the UUPC/extended license agreement.                         */
  19. /*--------------------------------------------------------------------*/
  20.  
  21. /*
  22.  *       $Id: dcpxfer.c 1.24 1993/10/02 22:56:59 ahd Exp $
  23.  *
  24.  *       $Log: dcpxfer.c $
  25.  * Revision 1.24  1993/10/02  22:56:59  ahd
  26.  * Suppress compile warning
  27.  *
  28.  * Revision 1.23  1993/09/23  03:26:51  ahd
  29.  * Don't allow remote sites to send call files!
  30.  *
  31.  * Revision 1.22  1993/09/20  04:46:34  ahd
  32.  * OS/2 2.x support (BC++ 1.0 support)
  33.  * TCP/IP support from Dave Watt
  34.  * 't' protocol support
  35.  *
  36.  * Revision 1.21  1993/09/02  12:08:17  ahd
  37.  * HPFS Support
  38.  *
  39.  * Revision 1.20  1993/08/08  17:39:09  ahd
  40.  * Denormalize path for opening on selected networks
  41.  *
  42.  * Revision 1.19  1993/07/22  23:22:27  ahd
  43.  * First pass at changes for Robert Denny's Windows 3.1 support
  44.  *
  45.  *
  46.  * Revision 1.17  1993/05/30  00:04:53  ahd
  47.  * Multiple communications drivers support
  48.  *
  49.  * Revision 1.16  1993/05/09  03:41:47  ahd
  50.  * Don't expand path of files destined for UUCP spool
  51.  * Correct syslog processing to not close when not multitasking
  52.  *
  53.  * Revision 1.15  1993/05/06  03:41:48  ahd
  54.  * Reformat syslog output into readable format
  55.  * parse userids off incoming commands again
  56.  *
  57.  * Revision 1.14  1993/04/11  00:34:11  ahd
  58.  * Global edits for year, TEXT, etc.
  59.  *
  60.  * Revision 1.13  1993/04/10  21:25:16  dmwatt
  61.  * Add Windows/NT support
  62.  *
  63.  * Revision 1.12  1993/04/05  04:35:40  ahd
  64.  * Allow unique send/receive packet sizes
  65.  *
  66.  * Revision 1.11  1993/01/23  19:08:09  ahd
  67.  * Don't enable unbuffered I/O twice if not multitask mode
  68.  *
  69.  * Revision 1.10  1992/12/01  04:37:03  ahd
  70.  * Suppress routine names transfered from debug level 0 and 1
  71.  *
  72.  * Revision 1.9  1992/11/29  22:09:10  ahd
  73.  * Change size_t to int to suppress warning message
  74.  *
  75.  * Revision 1.8  1992/11/28  19:51:16  ahd
  76.  * If in multitask mode, only open syslog on demand basis
  77.  *
  78.  * Revision 1.7  1992/11/22  21:20:45  ahd
  79.  * Make databuf char rather than unsigned char
  80.  *
  81.  * Revision 1.6  1992/11/20  12:39:10  ahd
  82.  * Add instead of substracting on the receive buffer!
  83.  *
  84.  * Revision 1.5  1992/11/19  03:01:31  ahd
  85.  * drop rcsid
  86.  *
  87.  * Revision 1.4  1992/11/19  02:36:12  ahd
  88.  * Insure log file is flushed
  89.  *
  90.  * Revision 1.3  1992/11/17  13:44:24  ahd
  91.  * Drop command[BUFSIZ], using databuf instead.
  92.  *
  93.  * Revision 1.2  1992/11/15  20:09:50  ahd
  94.  * Use unbuffered files to eliminate extra data copy
  95.  * Clean up modem file support for different protocols
  96.  *
  97.  */
  98.  
  99.  /*
  100.    Additional maintenance Notes:
  101.  
  102.    01Nov87 - that strncpy should be a memcpy! - Jal
  103.    22Jul90 - Add check for existence of the file before writing
  104.              it.                                                  ahd
  105.    09Apr91 - Add numerous changes from H.A.E.Broomhall and Cliff
  106.              Stanford for bidirectional support                   ahd
  107.    05Jul91 - Merged various changes from Jordan Brown's (HJB)
  108.              version of UUPC/extended to clean up transmission
  109.              of commands, etc.                                    ahd
  110.    09Jul91 - Rewrite to use unique routines for all four kinds of
  111.              transfers to allow for testing and security          ahd
  112.  */
  113.  
  114.  
  115. /*--------------------------------------------------------------------*/
  116. /*                        System include files                        */
  117. /*--------------------------------------------------------------------*/
  118.  
  119. #include <ctype.h>
  120. #include <fcntl.h>
  121. #include <direct.h>
  122. #include <io.h>
  123. #include <stdio.h>
  124. #include <stdlib.h>
  125. #include <string.h>
  126. #include <time.h>
  127. #include <sys/types.h>
  128. #include <sys/stat.h>
  129. #include <sys/timeb.h>
  130.  
  131. /*--------------------------------------------------------------------*/
  132. /*                    UUPC/extended include files                     */
  133. /*--------------------------------------------------------------------*/
  134.  
  135. #include "lib.h"
  136. #include "dcp.h"
  137. #include "dcpsys.h"
  138. #include "dcpxfer.h"
  139. #include "expath.h"
  140. #include "hlib.h"
  141. #include "hostable.h"
  142. #include "import.h"
  143. #include "security.h"
  144. #include "modem.h"
  145.  
  146. /*--------------------------------------------------------------------*/
  147. /*                          Global variables                          */
  148. /*--------------------------------------------------------------------*/
  149.  
  150. static char *databuf = NULL;
  151. static unsigned int xferBufSize = 0;
  152.  
  153. static char fName[FILENAME_MAX], tName[FILENAME_MAX], dName[FILENAME_MAX];
  154. static char *lName;           // Name to report in syslog
  155. static char type, cmdopts[16];
  156.  
  157. static long bytes;
  158. static struct timeb startTime;
  159.  
  160. static boolean spool = FALSE; /* Received file is into spool dir     */
  161. static char spolName[FILENAME_MAX];
  162.                               /* Final host name of file to be
  163.                                  received into spool directory       */
  164. static char tempName[FILENAME_MAX];
  165.                               /* Temp name used to create received
  166.                                  file                                */
  167. static char userid[20];
  168.  
  169. currentfile();
  170.  
  171. /*--------------------------------------------------------------------*/
  172. /*                    Internal function prototypes                    */
  173. /*--------------------------------------------------------------------*/
  174.  
  175. static boolean pktgetstr( char *s);
  176. static boolean pktsendstr( char *s );
  177. static void buf_init( void );
  178.  
  179. static int  bufill(char  *buffer);
  180. static int  bufwrite(char  *buffer,int  len);
  181.  
  182. /*************** SEND PROTOCOL ***************************/
  183.  
  184. /*--------------------------------------------------------------------*/
  185. /*    s d a t a                                                       */
  186. /*                                                                    */
  187. /*    Send File Data                                                  */
  188. /*--------------------------------------------------------------------*/
  189.  
  190. XFER_STATE sdata( void )
  191. {
  192.    int S_size;
  193.    int used = 0;
  194.  
  195.    S_size = bufill((char *) databuf);
  196.  
  197.    if (S_size == 0)                 /* Get data from file         */
  198.       return XFER_SENDEOF;          /* if EOF set state to that   */
  199.    else if (S_size == -1)           /* If error ...               */
  200.       return XFER_ABORT;            /* Toss file                  */
  201.  
  202.    do {
  203.       short xmit = min( (size_t) S_size - used , s_pktsize );
  204.  
  205.       if ((*sendpkt)((char *) databuf + used, xmit) != DCP_OK)
  206.                                     /* Send data fail?            */
  207.       {
  208.          fclose( xfer_stream );
  209.          xfer_stream = NULL;
  210.          return XFER_LOST;    /* Trouble!                         */
  211.       }
  212.       else
  213.          used += xmit;
  214.  
  215.    } while( S_size > used );
  216.  
  217.    return XFER_SENDDATA;   /* Remain in send state                */
  218.  
  219. } /*sdata*/
  220.  
  221.  
  222. /*--------------------------------------------------------------------*/
  223. /*    b u f i l l